home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickTime / QuickTime 3 Interfaces & Libs / QTDevWin / CIncludes / fenv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-21  |  11.9 KB  |  310 lines  |  [TEXT/dosa]

  1. /*
  2.      File:        fenv.h
  3.  
  4.      Contains:    Floating-Point environment for PowerPC and 68K
  5.  
  6.      Version:    Technology:    MathLib v2
  7.                  Release:    QuickTime 3.0
  8.  
  9.      Copyright:    © 1987-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __FENV__
  19. #define __FENV__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. #if TARGET_OS_MAC
  48. /*
  49.     A collection of functions designed to provide access to the floating
  50.     point environment for numerical programming. It is modeled after
  51.     the floating-point requirements in C9X.
  52.     
  53.     The file <fenv.h> declares many functions in support of numerical
  54.     programming.  It provides a set of environmental controls similar to
  55.     the ones found in <SANE.h>.  Programs that test flags or run under
  56.     non-default modes must do so under the effect of an enabling
  57.     "fenv_access" pragma.
  58. */
  59.  
  60. /********************************************************************************
  61. *                                                                                *
  62. *    fenv_t         is a type for representing the entire floating-point        *
  63. *                     environment in a single object.                              *
  64. *                                                                                *
  65. *     fexcept_t        is a type for representing the floating-point                *
  66. *                     exception flag state collectively.                           *
  67. *                                                                                *
  68. ********************************************************************************/
  69. #if TARGET_CPU_PPC
  70. typedef long                             fenv_t;
  71. typedef long                             fexcept_t;
  72. /*    Definitions of floating-point exception macros                          */
  73.  
  74. enum {
  75.     FE_INEXACT                    = 0x02000000,
  76.     FE_DIVBYZERO                = 0x04000000,
  77.     FE_UNDERFLOW                = 0x08000000,
  78.     FE_OVERFLOW                    = 0x10000000,
  79.     FE_INVALID                    = 0x20000000
  80. };
  81.  
  82.  
  83. /*    Definitions of rounding direction macros                                */
  84.  
  85. enum {
  86.     FE_TONEAREST                = 0x00000000,
  87.     FE_TOWARDZERO                = 0x00000001,
  88.     FE_UPWARD                    = 0x00000002,
  89.     FE_DOWNWARD                    = 0x00000003
  90. };
  91.  
  92. #endif  /* TARGET_CPU_PPC */
  93.  
  94. #if TARGET_CPU_68K
  95. #if TARGET_RT_MAC_68881
  96. typedef long                             fexcept_t;
  97.  
  98. struct fenv_t {
  99.     long                             FPCR;
  100.     long                             FPSR;
  101. };
  102. typedef struct fenv_t                    fenv_t;
  103.  
  104. enum {
  105.     FE_INEXACT                    = 0x00000008,                    /* ((long)(8))   */
  106.     FE_DIVBYZERO                = 0x00000010,                    /* ((long)(16))  */
  107.     FE_UNDERFLOW                = 0x00000020,                    /* ((long)(32))  */
  108.     FE_OVERFLOW                    = 0x00000040,                    /* ((long)(64))  */
  109.     FE_INVALID                    = 0x00000080                    /* ((long)(128)) */
  110. };
  111.  
  112. #else
  113.  
  114. typedef short                             fexcept_t;
  115. typedef short                             fenv_t;
  116.  
  117. enum {
  118.     FE_INVALID                    = 0x0001,                        /* ((short)(1))  */
  119.     FE_UNDERFLOW                = 0x0002,                        /* ((short)(2))  */
  120.     FE_OVERFLOW                    = 0x0004,                        /* ((short)(4))  */
  121.     FE_DIVBYZERO                = 0x0008,                        /* ((short)(8))  */
  122.     FE_INEXACT                    = 0x0010                        /* ((short)(16)) */
  123. };
  124.  
  125. #endif  /* TARGET_RT_MAC_68881 */
  126.  
  127.  
  128. enum {
  129.     FE_TONEAREST                = 0x0000,                        /* ((short)(0))  */
  130.     FE_UPWARD                    = 0x0001,                        /* ((short)(1))  */
  131.     FE_DOWNWARD                    = 0x0002,                        /* ((short)(2))  */
  132.     FE_TOWARDZERO                = 0x0003                        /* ((short)(3))  */
  133. };
  134.  
  135. /*    Definitions of rounding precision macros  (68K only)                    */
  136.  
  137. enum {
  138.     FE_LDBLPREC                    = 0x0000,                        /* ((short)(0))  */
  139.     FE_DBLPREC                    = 0x0001,                        /* ((short)(1))  */
  140.     FE_FLTPREC                    = 0x0002                        /* ((short)(2))  */
  141. };
  142.  
  143. #endif  /* TARGET_CPU_68K */
  144.  
  145. /*    The bitwise OR of all exception macros                                  */
  146.  
  147. #define      FE_ALL_EXCEPT     ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID )
  148. /*    Definition of pointer to IEEE default environment object                */
  149. extern fenv_t _FE_DFL_ENV;               /* default environment object        */
  150. #define FE_DFL_ENV &_FE_DFL_ENV          /* pointer to default environment    */
  151.  
  152. /*******************************************************************************
  153. *     The following functions provide access to the exception flags.  The      *
  154. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  155. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  156. *******************************************************************************/
  157. /*******************************************************************************
  158. *     The function "feclearexcept" clears the supported exceptions represented *
  159. *     by its argument.                                                         *
  160. *******************************************************************************/
  161. EXTERN_API_C( void ) feclearexcept(int excepts);
  162.  
  163.  
  164.  
  165. /*******************************************************************************
  166. *    The function "fegetexcept" stores a representation of the exception       *
  167. *     flags indicated by the argument "excepts" through the pointer argument   *
  168. *     "flagp".                                                                 *
  169. *******************************************************************************/
  170. EXTERN_API_C( void ) fegetexcept(fexcept_t *flagp, int excepts);
  171.  
  172.  
  173.  
  174. /*******************************************************************************
  175. *     The function "feraiseexcept" raises the supported exceptions             *
  176. *     represented by its argument.                                             *
  177. *******************************************************************************/
  178. EXTERN_API_C( void ) feraiseexcept(int excepts);
  179.  
  180.  
  181.  
  182. /*******************************************************************************
  183. *     The function "fesetexcept" sets or clears the exception flags indicated  *
  184. *     by the int argument "excepts" according to the representation in the     *
  185. *     object pointed to by the pointer argument "flagp".  The value of         *
  186. *     "*flagp" must have been set by a previous call to "fegetexcept".         *
  187. *     This function does not raise exceptions; it just sets the state of       *
  188. *     the flags.                                                               *
  189. *******************************************************************************/
  190. EXTERN_API_C( void ) fesetexcept(const fexcept_t *flagp, int excepts);
  191.  
  192.  
  193.  
  194. /*******************************************************************************
  195. *     The function "fetestexcept" determines which of the specified subset of  *
  196. *     the exception flags are currently set.  The argument "excepts" specifies *
  197. *     the exception flags to be queried as a bitwise OR of the exception       *
  198. *     macros.  This function returns the bitwise OR of the exception macros    *
  199. *     corresponding to the currently set exceptions included in "excepts".     *
  200. *******************************************************************************/
  201. EXTERN_API_C( int ) fetestexcept(int excepts);
  202.  
  203.  
  204.  
  205. /*******************************************************************************
  206. *     The following functions provide control of rounding direction modes.     *
  207. *******************************************************************************/
  208. /*******************************************************************************
  209. *     The function "fegetround" returns the value of the rounding direction    *
  210. *     macro which represents the current rounding direction.                   *
  211. *******************************************************************************/
  212. EXTERN_API_C( int ) fegetround(void );
  213.  
  214.  
  215.  
  216. /*******************************************************************************
  217. *     The function "fesetround" establishes the rounding direction represented *
  218. *     by its argument.  It returns nonzero if and only if the argument matches *
  219. *     a rounding direction macro.  If not, the rounding direction is not       *
  220. *     changed.                                                                 *
  221. *******************************************************************************/
  222. EXTERN_API_C( int ) fesetround(int round);
  223.  
  224.  
  225.  
  226. /*******************************************************************************
  227. *    The following functions manage the floating-point environment, exception  *
  228. *    flags and dynamic modes, as one entity.                                   *
  229. *******************************************************************************/
  230. /*******************************************************************************
  231. *     The function "fegetenv" stores the current floating-point environment    *
  232. *     in the object pointed to by its pointer argument "envp".                 *
  233. *******************************************************************************/
  234. EXTERN_API_C( void ) fegetenv(fenv_t *envp);
  235.  
  236.  
  237.  
  238. /*******************************************************************************
  239. *     The function "feholdexcept" saves the current environment in the object  *
  240. *     pointed to by its pointer argument "envp", clears the exception flags,   *
  241. *     and clears floating-point exception enables.  This function supersedes   *
  242. *     the SANE function "procentry", but it does not change the current        *
  243. *     rounding direction mode.                                                 *
  244. *******************************************************************************/
  245. EXTERN_API_C( int ) feholdexcept(fenv_t *envp);
  246.  
  247.  
  248.  
  249. /*******************************************************************************
  250. *     The function "fesetenv" installs the floating-point environment          *
  251. *     environment represented by the object pointed to by its argument         *
  252. *     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  253. *     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  254. *     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  255. *******************************************************************************/
  256. EXTERN_API_C( void ) fesetenv(const fenv_t *envp);
  257.  
  258.  
  259.  
  260. /*******************************************************************************
  261. *     The function "feupdateenv" saves the current exceptions into its         *
  262. *     automatic storage, installs the environment represented through its      *
  263. *     pointer argument "envp", and then re-raises the saved exceptions.        *
  264. *     This function, which supersedes the SANE function "procexit", can be     *
  265. *     used in conjunction with "feholdexcept" to write routines which hide     *
  266. *     spurious exceptions from their callers.                                  *
  267. *******************************************************************************/
  268. EXTERN_API_C( void ) feupdateenv(const fenv_t *envp);
  269.  
  270.  
  271.  
  272. #if TARGET_CPU_68K
  273. /*******************************************************************************
  274. *     The following functions provide control of rounding precision.           *
  275. *     Because the PowerPC does not provide this capability, these functions    *  
  276. *     are available only for the 68K Macintosh.  Rounding precision values     *
  277. *     are defined by the rounding precision macros.  These functions are       *
  278. *     equivalent to the SANE functions getprecision and setprecision.          *
  279. *******************************************************************************/
  280. EXTERN_API_C( int ) fegetprec(void );
  281.  
  282. EXTERN_API_C( int ) fesetprec(int precision);
  283.  
  284. #endif  /* TARGET_CPU_68K */
  285.  
  286. #endif  /* TARGET_OS_MAC */
  287.  
  288.  
  289.  
  290. #if PRAGMA_STRUCT_ALIGN
  291.     #pragma options align=reset
  292. #elif PRAGMA_STRUCT_PACKPUSH
  293.     #pragma pack(pop)
  294. #elif PRAGMA_STRUCT_PACK
  295.     #pragma pack()
  296. #endif
  297.  
  298. #ifdef PRAGMA_IMPORT_OFF
  299. #pragma import off
  300. #elif PRAGMA_IMPORT
  301. #pragma import reset
  302. #endif
  303.  
  304. #ifdef __cplusplus
  305. }
  306. #endif
  307.  
  308. #endif /* __FENV__ */
  309.  
  310.